# -*- coding:utf-8 -*-
# class Solution:
#     def NumberOf1Between1AndN_Solution(self, n):
#         # write code here
#         if n < 1:
#             return 0
#
#         res = 0
#         for i in range(1, n+1):
#             list_i = list(str(i))
#             for item in list_i:
#                 if item == '1':
#                     res += 1
#         return res

class Solution:
    def NumberOf1Between1AndN_Solution(self, n):
        if n < 1:
            return 0
        res = 0
        for i in range(1, n+1):
            cur = i
            while cur:
                if cur % 10 == 1:
                    res += 1
                cur = cur // 10
        return res
test = Solution()
print(test.NumberOf1Between1AndN_Solution(1))